---------------------------------------------------------------------------------
       log:  C:\papers\formateur\changemed.log
  log type:  text
 opened on:  12 Nov 2010, 19:29:23

. #delimit ;
delimiter now ;
. set mem 30m;
(30720k)

. /*clear matrix;*/
> /*clear mata; */
> 
> set more off;

. *     ***************************************************************** *;
. *     ***************************************************************** *;
. *       File-Name:  stata_mxl_predictprob.do                            *;
. *       Date:       November 9, 2010                                    *;
. *       Author:     GG/MG                                               *;
. *       Purpose:    Produce Tables 1 and 2 in AJPS paper                *;
. *       Input File:     europe.dta                                      *;
. *       Output File:    stata_mxl_predictprob.log                       *;
. *       Data Output:    none                                            *;
. *       Previous file:  europe.dta                                      *;
. *       Machine:        Matt's desktop                                  *;
. *     ****************************************************************  *;
. *     ****************************************************************  *;
. use "europe.dta", clear;

. *     ****************************************************************  *;
. *       Model 6: Western Europe                                         *;
. *     ****************************************************************  *;
. mixlogit choice largestparty_east party_seatshare_east medianparty1_east pres
> identparty_east previousPM_east previousPM_conflict_east previousPM_gain1_eas
> t previous_cabinet_gain1_east,  
>     rand (largestparty party_seatshare medianparty1 presidentparty previousPM
>  president_investiture president_direct previousPM_conflict previousPM_gain1 
> previous_cabinet_gain1) 
>     ln(0) nrep(125) group(cabinetcode);

Iteration 0:   log likelihood = -255.29786  (not concave)
Iteration 1:   log likelihood = -245.38797  (not concave)
Iteration 2:   log likelihood =  -228.8695  
Iteration 3:   log likelihood = -221.24204  (not concave)
Iteration 4:   log likelihood = -221.16184  (not concave)
Iteration 5:   log likelihood = -220.39987  
Iteration 6:   log likelihood = -219.61402  
Iteration 7:   log likelihood = -219.46931  
Iteration 8:   log likelihood = -219.42816  (not concave)
Iteration 9:   log likelihood = -219.41127  (not concave)
Iteration 10:  log likelihood = -219.40734  (not concave)
Iteration 11:  log likelihood = -219.38014  
Iteration 12:  log likelihood = -219.35916  
Iteration 13:  log likelihood = -219.35268  
Iteration 14:  log likelihood = -219.35266  

Mixed logit model                                 Number of obs   =       2039
                                                  LR chi2(10)     =      19.54
Log likelihood = -219.35266                       Prob > chi2     =     0.0339

------------------------------------------------------------------------------
      choice |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
Mean         |
largestp~ast |  -1.253544   2.017873    -0.62   0.534    -5.208503    2.701414
party_se~ast |   .2877481   .1444587     1.99   0.046     .0046143    .5708819
medianpa~ast |  -3.117227   1.721757    -1.81   0.070    -6.491809    .2573546
presi~y_east |  -.4970681   1.853252    -0.27   0.789    -4.129376     3.13524
previ~M_east |   -2.19965   2.606521    -0.84   0.399    -7.308337    2.909037
previ~t_east |   1.126725   3.208478     0.35   0.725    -5.161776    7.415226
previousPM.. |  -.0930831   .4810077    -0.19   0.847    -1.035841    .8496747
previous_c.. |   .0517841   .1988117     0.26   0.795    -.3378797    .4414479
largestparty |   2.109019   1.104417     1.91   0.056    -.0555996    4.273637
party_seat~e |   .1351541   .0258657     5.23   0.000     .0844583    .1858499
medianparty1 |   1.392319   .3828235     3.64   0.000     .6419985    2.142639
presidentp~y |   5.250695   2.428888     2.16   0.031      .490162    10.01123
  previousPM |   2.841572   1.038968     2.73   0.006     .8052325    4.877912
president_~e |  -3.060496   2.130412    -1.44   0.151    -7.236027    1.115035
president~ct |  -3.915977     2.1442    -1.83   0.068    -8.118531    .2865775
previousP~ct |  -2.618633   1.261868    -2.08   0.038    -5.091848   -.1454174
previousPM~1 |   .4958572   .2007184     2.47   0.013     .1024564     .889258
previous_c~1 |   .0367127   .0403208     0.91   0.363    -.0423147    .1157401
-------------+----------------------------------------------------------------
SD           |
largestparty |   -4.72622   1.779758    -2.66   0.008    -8.214482   -1.237957
party_seat~e |  -.0074871   .0352742    -0.21   0.832    -.0766233    .0616491
medianparty1 |    .137813   .9798871     0.14   0.888     -1.78273    2.058357
presidentp~y |   -.266903   1.275177    -0.21   0.834    -2.766204    2.232398
  previousPM |   -1.90488   1.048407    -1.82   0.069     -3.95972    .1499603
president_~e |  -.4246113   1.592647    -0.27   0.790    -3.546143     2.69692
president~ct |    .591708    1.45034     0.41   0.683    -2.250906    3.434321
previousP~ct |  -.1339581   2.773063    -0.05   0.961    -5.569061    5.301145
previousPM~1 |     .11201   .2052589     0.55   0.585      -.29029      .51431
previous_c~1 |   .1484155   .0862285     1.72   0.085    -.0205892    .3174201
------------------------------------------------------------------------------

.     *     ****************************************************************  *
> ;
. *       Now produce Figure 1                                            *;
. *     ****************************************************************  *;
. matrix coeffs = e(b);

. matrix covmat = e(V);

. keep if cabinetcode==1222;
(2400 observations deleted)

. set obs 10000;
obs was 12, now 10000

. generate pvda = 0;

. replace pvda = 1 if partyID==7;
(1 real change made)

. generate cda = 0;

. replace cda = 1 if partyID==13;
(1 real change made)

. generate vvd = 0;

. replace vvd = 1 if partyID==22;
(1 real change made)

. generate d66 = 0;

. replace d66 = 1 if partyID==10;
(1 real change made)

. generate ppvda1 = .;
(10000 missing values generated)

. generate pcda1 = .;
(10000 missing values generated)

. generate pvvd1 = .;
(10000 missing values generated)

. generate pd661 = .;
(10000 missing values generated)

. generate ppvda2 = .;
(10000 missing values generated)

. generate pcda2 = .;
(10000 missing values generated)

. generate pvvd2 = .;
(10000 missing values generated)

. generate pd662 = .;
(10000 missing values generated)

. generate ppvda3 = .;
(10000 missing values generated)

. generate pcda3 = .;
(10000 missing values generated)

. generate pvvd3 = .;
(10000 missing values generated)

. generate pd663 = .;
(10000 missing values generated)

. generate ppvda4 = .;
(10000 missing values generated)

. generate pcda4 = .;
(10000 missing values generated)

. generate pvvd4 = .;
(10000 missing values generated)

. generate pd664 = .;
(10000 missing values generated)

. drawnorm b1-b28, means(coeffs) cov(covmat) double;

.  nois _dots 0, title(median party sim) reps(10000);
median party sim (10000)
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5 

. forvalues j = 1/10000 {;
  2.   mkmat b1-b28 if _n==`j', matrix(bdraw);
  3.   mixlpred2 pprobs;
  4.    qui generate pt1 = pprobs * pvda;
  5.   qui generate ct1 = pprobs * cda;
  6.   qui generate vt1 = pprobs * vvd;
  7.   qui generate dt1 = pprobs * d66;
  8.   qui replace medianparty1 = 0 if cda==1;
  9.   qui replace medianparty1 = 1 if pvda==1;
 10. mixlpred2 pprobs2;
 11.   qui generate pt2 = pprobs2 * pvda;
 12.   qui generate ct2 = pprobs2 * cda;
 13.   qui generate vt2 = pprobs2 * vvd;
 14.   qui generate dt2 = pprobs2 * d66;
 15.   qui replace medianparty1 = 0 if pvda==1;
 16.   qui replace medianparty1 = 1 if vvd==1;
 17. mixlpred2 pprobs3;
 18.   qui generate pt3 = pprobs3 * pvda;
 19.   qui generate ct3 = pprobs3 * cda;
 20.   qui generate vt3 = pprobs3 * vvd;
 21.   qui generate dt3 = pprobs3 * d66;
 22.   qui replace medianparty1 = 0 if vvd==1;
 23.   qui replace medianparty1 = 1 if d66==1;
 24. mixlpred2 pprobs4;
 25.   qui generate pt4 = pprobs4 * pvda;
 26.   qui generate ct4 = pprobs4 * cda;
 27.   qui generate vt4 = pprobs4 * vvd;
 28.   qui generate dt4 = pprobs4 * d66;
 29.   qui replace medianparty1 = 1 if cda==1;
 30.   qui replace medianparty1 = 0 if d66==1;
 31.   egen pt1s = sum(pt1);
 32.   egen ct1s = sum(ct1);
 33.   egen vt1s = sum(vt1);
 34.   egen dt1s = sum(dt1);
 35.   egen pt2s = sum(pt2);
 36.   egen ct2s = sum(ct2);
 37.   egen vt2s = sum(vt2);
 38.   egen dt2s = sum(dt2);
 39.   egen pt3s = sum(pt3);
 40.   egen ct3s = sum(ct3);
 41.   egen vt3s = sum(vt3);
 42.   egen dt3s = sum(dt3);
 43.   egen pt4s = sum(pt4);
 44.   egen ct4s = sum(ct4);
 45.   egen vt4s = sum(vt4);
 46.   egen dt4s = sum(dt4);
 47.   qui replace ppvda1 = pt1s if _n==`j';
 48.   qui replace pcda1 = ct1s if _n==`j';
 49.   qui replace pvvd1 = vt1s if _n==`j';
 50.   qui replace pd661 = dt1s if _n==`j';
 51.   qui replace ppvda2 = pt2s if _n==`j';
 52.   qui replace pcda2 = ct2s if _n==`j';
 53.   qui replace pvvd2 = vt2s if _n==`j';
 54.   qui replace pd662 = dt2s if _n==`j';
 55.   qui replace ppvda3 = pt3s if _n==`j';
 56.   qui replace pcda3 = ct3s if _n==`j';
 57.   qui replace pvvd3 = vt3s if _n==`j';
 58.   qui replace pd663 = dt3s if _n==`j';
 59.   qui replace ppvda4 = pt4s if _n==`j';
 60.   qui replace pcda4 = ct4s if _n==`j';
 61.   qui replace pvvd4 = vt4s if _n==`j';
 62.   qui replace pd664 = dt4s if _n==`j';
 63. drop pt1 ct1 vt1 dt1 pt2 ct2 vt2 dt2 pt3 ct3 vt3 dt3 pt4 ct4 vt4 dt4 
> pt1s ct1s vt1s dt1s pt2s ct2s vt2s dt2s pt3s ct3s vt3s dt3s pt4s ct4s vt4s dt
> 4s 
> pprobs pprobs2 pprobs3 pprobs4;
 64.  nois _dots `j' 0;
 65.   };
..................................................    50
..................................................   100
..................................................   150
..................................................   200
..................................................   250
..................................................   300
..................................................   350
..................................................   400
..................................................   450
..................................................   500
..................................................   550
..................................................   600
..................................................   650
..................................................   700
..................................................   750
..................................................   800
..................................................   850
..................................................   900
..................................................   950
..................................................  1000
..................................................  1050
..................................................  1100
..................................................  1150
..................................................  1200
..................................................  1250
..................................................  1300
..................................................  1350
..................................................  1400
..................................................  1450
..................................................  1500
..................................................  1550
..................................................  1600
..................................................  1650
..................................................  1700
..................................................  1750
..................................................  1800
..................................................  1850
..................................................  1900
..................................................  1950
..................................................  2000
..................................................  2050
..................................................  2100
..................................................  2150
..................................................  2200
..................................................  2250
..................................................  2300
..................................................  2350
..................................................  2400
..................................................  2450
..................................................  2500
..................................................  2550
..................................................  2600
..................................................  2650
..................................................  2700
..................................................  2750
..................................................  2800
..................................................  2850
..................................................  2900
..................................................  2950
..................................................  3000
..................................................  3050
..................................................  3100
..................................................  3150
..................................................  3200
..................................................  3250
..................................................  3300
..................................................  3350
..................................................  3400
..................................................  3450
..................................................  3500
..................................................  3550
..................................................  3600
..................................................  3650
..................................................  3700
..................................................  3750
..................................................  3800
..................................................  3850
..................................................  3900
..................................................  3950
..................................................  4000
..................................................  4050
..................................................  4100
..................................................  4150
..................................................  4200
..................................................  4250
..................................................  4300
..................................................  4350
..................................................  4400
..................................................  4450
..................................................  4500
..................................................  4550
..................................................  4600
..................................................  4650
..................................................  4700
..................................................  4750
..................................................  4800
..................................................  4850
..................................................  4900
..................................................  4950
..................................................  5000
..................................................  5050
..................................................  5100
..................................................  5150
..................................................  5200
..................................................  5250
..................................................  5300
..................................................  5350
..................................................  5400
..................................................  5450
..................................................  5500
..................................................  5550
..................................................  5600
..................................................  5650
..................................................  5700
..................................................  5750
..................................................  5800
..................................................  5850
..................................................  5900
..................................................  5950
..................................................  6000
..................................................  6050
..................................................  6100
..................................................  6150
..................................................  6200
..................................................  6250
..................................................  6300
..................................................  6350
..................................................  6400
..................................................  6450
..................................................  6500
..................................................  6550
..................................................  6600
..................................................  6650
..................................................  6700
..................................................  6750
..................................................  6800
..................................................  6850
..................................................  6900
..................................................  6950
..................................................  7000
..................................................  7050
..................................................  7100
..................................................  7150
..................................................  7200
..................................................  7250
..................................................  7300
..................................................  7350
..................................................  7400
..................................................  7450
..................................................  7500
..................................................  7550
..................................................  7600
..................................................  7650
..................................................  7700
..................................................  7750
..................................................  7800
..................................................  7850
..................................................  7900
..................................................  7950
..................................................  8000
..................................................  8050
..................................................  8100
..................................................  8150
..................................................  8200
..................................................  8250
..................................................  8300
..................................................  8350
..................................................  8400
..................................................  8450
..................................................  8500
..................................................  8550
..................................................  8600
..................................................  8650
..................................................  8700
..................................................  8750
..................................................  8800
..................................................  8850
..................................................  8900
..................................................  8950
..................................................  9000
..................................................  9050
..................................................  9100
..................................................  9150
..................................................  9200
..................................................  9250
..................................................  9300
..................................................  9350
..................................................  9400
..................................................  9450
..................................................  9500
..................................................  9550
..................................................  9600
..................................................  9650
..................................................  9700
..................................................  9750
..................................................  9800
..................................................  9850
..................................................  9900
..................................................  9950
.................................................. 10000

. generate pvdad2 = ppvda2 - ppvda1;

. generate pvdad3 = ppvda3 - ppvda1;

. generate pvdad4 = ppvda4 - ppvda1;

. generate cdad2 = pcda2 - pcda1;

. generate cdad3 = pcda3 - pcda1;

. generate cdad4 = pcda4 - pcda1;

. generate vvdd2 = pvvd2 - pvvd1;

. generate vvdd3 = pvvd3 - pvvd1;

. generate vvdd4 = pvvd4 - pvvd1;

. generate d66d2 = pd662 - pd661;

. generate d66d3 = pd663 - pd661;

. generate d66d4 = pd664 - pd661;

. summarize 
> ppvda1 pcda1 pvvd1 pd661
> ppvda2 pcda2 pvvd2 pd662
> ppvda3 pcda3 pvvd3 pd663
> ppvda4 pcda4 pvvd4 pd664
> pvdad2 cdad2 vvdd2 d66d2
> pvdad3 cdad3 vvdd3 d66d3
> pvdad4 cdad4 vvdd4 d66d4;

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
      ppvda1 |     10000    .5773832    .1025367   .0105241    .773866
       pcda1 |     10000     .143042    .1034168   .0003944   .8688393
       pvvd1 |     10000    .1229365    .0325492   .0276582   .3235207
       pd661 |     10000    .0639232    .0148604   .0139242   .1705652
      ppvda2 |     10000    .7027586    .0771263   .0529719   .9166577
-------------+--------------------------------------------------------
       pcda2 |     10000    .0695794    .0653676   .0000663   .7450995
       pvvd2 |     10000    .1004306    .0282765   .0203654   .2477081
       pd662 |     10000    .0521241    .0125914   .0120181   .1290124
      ppvda3 |     10000     .535969    .1025093   .0129859   .7303637
       pcda3 |     10000    .0703076    .0683726   .0000397   .7031999
-------------+--------------------------------------------------------
       pvvd3 |     10000     .290301    .0709411   .0959985   .7488303
       pd663 |     10000    .0406124    .0127336   .0116696    .123366
      ppvda4 |     10000    .5568001    .0999868   .0146664   .7438783
       pcda4 |     10000    .0748184    .0710844   .0000526   .7166035
       pvvd4 |     10000    .0917222    .0252866   .0287805   .2433497
-------------+--------------------------------------------------------
       pd664 |     10000    .2052396      .05714   .0643271   .5824177
      pvdad2 |     10000    .1253753     .057498  -.0221854   .4528597
       cdad2 |     10000   -.0734626    .0516661  -.4227097   .0145047
       vvdd2 |     10000   -.0225059    .0157528  -.1285498   .0416908
       d66d2 |     10000   -.0117991    .0083185  -.0714033   .0233208
-------------+--------------------------------------------------------
      pvdad3 |     10000   -.0414142     .028274  -.2301109   .0835104
       cdad3 |     10000   -.0727344    .0500023  -.4324046   .0155511
       vvdd3 |     10000    .1673645    .0589706  -.0122362   .4849942
       d66d3 |     10000   -.0233108    .0108957  -.0889313    .016846
      pvdad4 |     10000   -.0205831    .0224192   -.167219   .1006978
-------------+--------------------------------------------------------
       cdad4 |     10000   -.0682236    .0468032  -.4030982   .0180678
       vvdd4 |     10000   -.0312143    .0184342  -.1300639   .0326616
       d66d4 |     10000    .1413164    .0516166  -.0076275   .4517714

. 
end of do-file


. exit, clear
